<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>使用指南 | vue-super-tree | 给力的 Tree 组件</title>
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" href="/vue-super-tree/assets/img/logo.png">
    <meta name="description" content="基于 Vue@2 开发的 Tree 组件，支持海量树节点渲染和一些自定义属性。">
    
    <link rel="preload" href="/vue-super-tree/assets/css/0.styles.0706cd2b.css" as="style"><link rel="preload" href="/vue-super-tree/assets/js/app.0a25f3ae.js" as="script"><link rel="preload" href="/vue-super-tree/assets/js/2.e8bb647d.js" as="script"><link rel="preload" href="/vue-super-tree/assets/js/11.c02c8573.js" as="script"><link rel="prefetch" href="/vue-super-tree/assets/js/10.76ce0b25.js"><link rel="prefetch" href="/vue-super-tree/assets/js/12.eea6eda7.js"><link rel="prefetch" href="/vue-super-tree/assets/js/3.e01f49b9.js"><link rel="prefetch" href="/vue-super-tree/assets/js/4.c4231f20.js"><link rel="prefetch" href="/vue-super-tree/assets/js/5.2427f0c1.js"><link rel="prefetch" href="/vue-super-tree/assets/js/6.84419979.js"><link rel="prefetch" href="/vue-super-tree/assets/js/7.79c55155.js"><link rel="prefetch" href="/vue-super-tree/assets/js/8.9ea141c9.js"><link rel="prefetch" href="/vue-super-tree/assets/js/9.c9c2ea78.js">
    <link rel="stylesheet" href="/vue-super-tree/assets/css/0.styles.0706cd2b.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/vue-super-tree/" class="home-link router-link-active"><img src="/vue-super-tree/assets/img/logo.png" alt="vue-super-tree | 给力的 Tree 组件" class="logo"> <span class="site-name can-hide">vue-super-tree | 给力的 Tree 组件</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/vue-super-tree/" class="nav-link">
  首页
</a></div><div class="nav-item"><a href="/vue-super-tree/guide/" aria-current="page" class="nav-link router-link-exact-active router-link-active">
  使用指南
</a></div><div class="nav-item"><a href="/vue-super-tree/demo/" class="nav-link">
  示例
</a></div> <a href="https://github.com/self-denial-cy/vue-super-tree" target="_blank" rel="noopener noreferrer" class="repo-link">
    查看源码
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/vue-super-tree/" class="nav-link">
  首页
</a></div><div class="nav-item"><a href="/vue-super-tree/guide/" aria-current="page" class="nav-link router-link-exact-active router-link-active">
  使用指南
</a></div><div class="nav-item"><a href="/vue-super-tree/demo/" class="nav-link">
  示例
</a></div> <a href="https://github.com/self-denial-cy/vue-super-tree" target="_blank" rel="noopener noreferrer" class="repo-link">
    查看源码
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>使用指南</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/vue-super-tree/guide/#安装和使用" class="sidebar-link">安装和使用</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/vue-super-tree/guide/#npm引入" class="sidebar-link">npm引入</a></li><li class="sidebar-sub-header"><a href="/vue-super-tree/guide/#script标签引用" class="sidebar-link">script标签引用</a></li></ul></li><li><a href="/vue-super-tree/guide/#支持的组件属性" class="sidebar-link">支持的组件属性</a><ul class="sidebar-sub-headers"></ul></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="使用指南"><a href="#使用指南" class="header-anchor">#</a> 使用指南</h1> <h2 id="安装和使用"><a href="#安装和使用" class="header-anchor">#</a> 安装和使用</h2> <h3 id="npm引入"><a href="#npm引入" class="header-anchor">#</a> npm引入</h3> <h4 id="安装"><a href="#安装" class="header-anchor">#</a> 安装</h4> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token function">npm</span> <span class="token function">install</span> --save @self-denial-cy/vue-super-tree
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="使用"><a href="#使用" class="header-anchor">#</a> 使用</h4> <h5 id="全局注册"><a href="#全局注册" class="header-anchor">#</a> 全局注册</h5> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">import</span> Vue <span class="token keyword">from</span> <span class="token string">'vue'</span>
<span class="token keyword">import</span> VueSuperTree <span class="token keyword">from</span> <span class="token string">&quot;@self-denial-cy/vue-super-tree&quot;</span>
Vue<span class="token punctuation">.</span><span class="token function">use</span><span class="token punctuation">(</span>VueSuperTree<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h5 id="局部引入组件"><a href="#局部引入组件" class="header-anchor">#</a> 局部引入组件</h5> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">import</span> VueSuperTree <span class="token keyword">from</span> <span class="token string">&quot;@self-denial-cy/vue-super-tree&quot;</span>

<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
    <span class="token literal-property property">components</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        VueSuperTree
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token comment">// 其他代码</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><h5 id="使用示例"><a href="#使用示例" class="header-anchor">#</a> 使用示例</h5> <div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>app<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>vue-super-tree</span>
    <span class="token attr-name">:tree</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>treeData<span class="token punctuation">&quot;</span></span>
    <span class="token attr-name">valueKey</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>_key<span class="token punctuation">&quot;</span></span>
    <span class="token attr-name">:height</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>height<span class="token punctuation">&quot;</span></span>
    <span class="token attr-name">:padding</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>36<span class="token punctuation">&quot;</span></span>
  <span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>template</span> <span class="token attr-name">v-slot</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>{ item }<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>{{ item._key }}<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>template</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>vue-super-tree</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">import</span> treeData <span class="token keyword">from</span> <span class="token string">&quot;./api/index&quot;</span><span class="token punctuation">;</span>

<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
  <span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">&quot;App&quot;</span><span class="token punctuation">,</span>
  <span class="token function">data</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token punctuation">{</span>
      treeData<span class="token punctuation">,</span>
      <span class="token literal-property property">height</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token function">created</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>height <span class="token operator">=</span> document<span class="token punctuation">.</span>documentElement<span class="token punctuation">.</span>clientHeight <span class="token operator">-</span> <span class="token number">16</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><h3 id="script标签引用"><a href="#script标签引用" class="header-anchor">#</a> script标签引用</h3> <div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token doctype"><span class="token punctuation">&lt;!</span><span class="token doctype-tag">DOCTYPE</span> <span class="token name">html</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>html</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>head</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>https://cdn.bootcss.com/vue/2.6.11/vue.min.js<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token script"></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>path-to/vue-super-tree.umd.min.js<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token script"></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>head</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>app<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span><span class="token punctuation">&gt;</span></span><span class="token script"><span class="token language-javascript">
    <span class="token keyword">new</span> <span class="token class-name">Vue</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
      <span class="token literal-property property">el</span><span class="token operator">:</span> <span class="token string">&quot;#app&quot;</span><span class="token punctuation">,</span>
      <span class="token literal-property property">template</span><span class="token operator">:</span> <span class="token string">'&lt;vue-super-tree :tree=&quot;treeData&quot;&gt;&lt;/vue-super-tree&gt;'</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span>
  </span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>html</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><h2 id="支持的组件属性"><a href="#支持的组件属性" class="header-anchor">#</a> 支持的组件属性</h2> <table><thead><tr><th style="text-align:center;">参数</th> <th style="text-align:left;">说明</th> <th style="text-align:center;">类型</th> <th style="text-align:center;">是否必传</th> <th style="text-align:center;">默认值</th></tr></thead> <tbody><tr><td style="text-align:center;">tree</td> <td style="text-align:left;">树形结构数据</td> <td style="text-align:center;">Array</td> <td style="text-align:center;">true</td> <td style="text-align:center;">[]</td></tr> <tr><td style="text-align:center;">defaultExpand</td> <td style="text-align:left;">是否默认展开</td> <td style="text-align:center;">Boolean</td> <td style="text-align:center;">false</td> <td style="text-align:center;">false</td></tr> <tr><td style="text-align:center;">timeout</td> <td style="text-align:left;">刷新频率（数值越低越精确，但是性能消耗也会大大增加）</td> <td style="text-align:center;">Number</td> <td style="text-align:center;">false</td> <td style="text-align:center;">8</td></tr> <tr><td style="text-align:center;">height</td> <td style="text-align:left;">滚动容器的高度</td> <td style="text-align:center;">Number</td> <td style="text-align:center;">false</td> <td style="text-align:center;">720</td></tr> <tr><td style="text-align:center;">itemHeight</td> <td style="text-align:left;">单个 item 的高度</td> <td style="text-align:center;">Number</td> <td style="text-align:center;">false</td> <td style="text-align:center;">32</td></tr> <tr><td style="text-align:center;">childrenKey</td> <td style="text-align:left;">children 字段的 key</td> <td style="text-align:center;">String</td> <td style="text-align:center;">false</td> <td style="text-align:center;">children</td></tr> <tr><td style="text-align:center;">valueKey</td> <td style="text-align:left;">value 字段的 key</td> <td style="text-align:center;">String</td> <td style="text-align:center;">false</td> <td style="text-align:center;">value</td></tr> <tr><td style="text-align:center;">expandKey</td> <td style="text-align:left;">expand 字段的 key</td> <td style="text-align:center;">String</td> <td style="text-align:center;">false</td> <td style="text-align:center;">expand</td></tr> <tr><td style="text-align:center;">padding</td> <td style="text-align:left;">节点的段间距</td> <td style="text-align:center;">Number</td> <td style="text-align:center;">false</td> <td style="text-align:center;">24</td></tr></tbody></table></div> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">Last Updated:</span> <span class="time">6/5/2022, 6:05:10 PM</span></div></footer> <!----> </main></div><div class="global-ui"></div></div>
    <script src="/vue-super-tree/assets/js/app.0a25f3ae.js" defer></script><script src="/vue-super-tree/assets/js/2.e8bb647d.js" defer></script><script src="/vue-super-tree/assets/js/11.c02c8573.js" defer></script>
  </body>
</html>
